package cc.kigh.framework.handler;

import cc.kigh.common.utils.DateUtils;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.springframework.core.convert.converter.Converter;

import java.io.IOException;
import java.util.Date;

/**
 * @author gylang
 * data 2022/2/25
 */
public class DateDeserializer extends JsonDeserializer<Date> implements Converter<String, Date> {

    public static final DateDeserializer INSTANCE = new DateDeserializer();
    @Override
    public Date convert(String source) {
        return DateUtils.parseDate(source);
    }

    @Override
    public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        return DateUtils.parseDate(p.getText());
    }
}
